pascal OSErr HDeleteFork(short vRefNum, long dirID, ConstStr255Param fileName, Boolean isResourceFork); /* [[paragraph]] Delete a fork of a file without deleting the file. The HDeleteFork function deletes a file's data or resource fork. The isResourceFork parameter specifies the fork to delete. vRefNum input: Volume specification. dirID input: Directory ID. fileName input: The name of the file. isResourceFork input: The file fork to delete. If true, the resource fork is deleted; if false, the data fork is deleted. */ pascal OSErr HDeleteFork(short vRefNum, long dirID, ConstStr255Param fileName, Boolean isResourceFork) { OSErr result; short refNum; if ( isResourceFork ) { result = HOpenRF(vRefNum, dirID, fileName, fsRdWrPerm, &refNum); } else { result = HOpenDF(vRefNum, dirID, fileName, fsRdWrPerm, &refNum); if ( result == paramErr ) { /* HOpenDF isn't supported under System 6, so retry with HOpen */ result = HOpen(vRefNum, dirID, fileName, fsRdWrPerm, &refNum); } } if ( result == noErr ) { result = SetEOF(refNum, 0); (void) FSClose(refNum); } return ( result ); }
On HFS volumes, setting a file fork's EOF to zero releases all allocation
blocks associated with the file. However, some foreign file systems add
information to the volume's catalog when a resource fork is added and don't
remove that data when you set the EOF to zero. For example, on ProDOS volumes,
opening a resource fork for a file changes the file to an "extended" file,
which can only be opened with GS/OS on an Apple IIgs (extended ProDOS files
cannot be opened by ProDOS 8 on an Apple II). With file systems that exhibit this behavior, the only way to remove all traces of the file's resource fork is to copy the file's data fork, and then delete the original file. The MoreFiles sample code on the Tool Chest edition
of the Developer CD includes a routine called CopyFork that copies only the
data fork.
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help